n = int(input())
h = list(map(int, input().split()))


def f(e):
    for i in range(n):
        if h[i] > e:
            e -= h[i] - e
        else:
            e += e - h[i]
        if e < 0:
            return False
    return True


left = 0
right = max(h)
while left <= right:
    mid = (left + right) >> 1
    if f(mid):
        right = mid - 1
    else:
        left = mid + 1
print(right + 1)
